package com.tour.tour.controller;

import com.tour.tour.common.Response;
import com.tour.tour.entity.SpotInfo;
import com.tour.tour.service.SpotInfoService;
import com.tour.tour.vo.SpotInfoVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author YounGCY
 * @date 2023-5-16 上午 3:07
 * @description
 */
@RestController
@RequestMapping("/spots")
@CrossOrigin
public class SpotInfoController {
    
    @Resource
    private SpotInfoService spotInfoService;
    
    public Response add(@RequestBody SpotInfo spotInfo) {
        spotInfoService.save(spotInfo);
        return Response.success(spotInfo.getId());
    }
    
    @GetMapping("/{id}")
    public Response queryById(@PathVariable("id") Integer id) {
        return Response.success(spotInfoService.getById(id));
    }
    
    @PutMapping("/update")
    public Response update(@RequestBody SpotInfo spotInfo) {
        spotInfoService.updateById(spotInfo);
        return Response.success();
    }
    
    @GetMapping("/page")
    public Response<List<SpotInfoVO>> getPage(@RequestParam(value = "current", defaultValue = "1") Integer current) {
        return spotInfoService.getPage(current);
    }

    @DeleteMapping("/delete")
    public Response<Void> delete(Long id){
        spotInfoService.removeById(id);
        return Response.success();
    }
    
}
